package forum.business.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import forum.business.entities.UserBO;
import forum.util.exceptions.AdException;

public class UserDAO extends DAO {

	public UserDAO() {}

	public UserBO createUser(UserBO user) throws AdException {
		getSession().save(user);
		return user;
	}

	public List<UserBO> listUsers() {
		return getSession().createQuery("from UserBO").list();
	}

	public void removeUser(String login) {
		getSession().createQuery("delete UserBO where login = :login")
				.setString("login", login);

	}
	
	public void updateUser(UserBO userBO) {
		getSession().update(userBO);
		/*
		getSession().createQuery("update UserBO u set c = :user where login = :login")
		.setEntity("user", userBO)
		.setString("login", login);
		*/
	}
	
	
	public UserBO getUser(String login){
		 Query query = getSession().createQuery("from UserBO where login = :login")
				.setString("login", login);
		 return (UserBO) query.uniqueResult();
	}
}
